Isomporphic Strings
August 20, 2016
Just used a hashmap as a mapping technique and created a getKey function to have bijection mapping.
Full Solution in Java:
public class Solution { public boolean isIsomorphic(String s, String t) { HashMap< Character,Character> maps = new HashMap< Character,Character>(); for(int i=0; i< s.length(); i++){ char c = s.charAt(i); char x = t.charAt(i); if(maps.containsKey(c)){ if(x!=maps.get(c)){ return false; } } else if(maps.containsValue(x)){ if(c!=getKey(maps, x)){ return false; } } else{ maps.put(c,x); } } return true; } static Character getKey(HashMap< Character,Character> maps, char value){ for ( char key : maps.keySet() ) { if(maps.get(key)==value){ return key; } } return null; } }